<!DOCTYPE html>
<html lang="zh">

<head>
    <meta charset="UTF-8"/>
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

    <title>提币申请</title>

    <link href="../plugin/bootstrap-3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
    <link href="../plugin/bootstrap-table-1.11.1/bootstrap-table.min.css" rel="stylesheet"/>
    <link href="../plugin/sweetalert-6.6.2/sweetalert2.min.css" rel="stylesheet"/>
    <link href="../plugin/bootstrap-3.3.7/plugin/file_input/fileinput.min.css" rel="stylesheet"/>
    <link href="../plugin/bootstrap-3.3.7/plugin/datatimepicker/bootstrap-datetimepicker.min.css" rel="stylesheet"/>
    <link href="../plugin/jquery-zoomify/zoomify.min.css" rel="stylesheet"/>

    <script src="../plugin/jquery-3.2.1/jquery-3.2.1.min.js"></script>
    <script src="../plugin/bootstrap-3.3.7/js/bootstrap.min.js"></script>
    <script src="../plugin/bootstrap-3.3.7/plugin/file_input/fileinput.min.js"></script>
    <script src="../plugin/bootstrap-3.3.7/plugin/file_input/local_zh.js"></script>
    <script src="../plugin/bootstrap-3.3.7/plugin/datatimepicker/bootstrap-datetimepicker.min.js"></script>
    <script src="../plugin/bootstrap-3.3.7/plugin/datatimepicker/bootstrap-datetimepicker.zh-CN.js"></script>
    <script src="../plugin/bootstrap-table-1.11.1/bootstrap-table.min.js"></script>
    <script src="../plugin/bootstrap-table-1.11.1/locale/bootstrap-table-zh-CN.min.js"></script>
    <script src="../plugin/sweetalert-6.6.2/sweetalert2.min.js"></script>
    <script src="../plugin/jquery-3.2.1/jquery.formautofill.min.js"></script>
    <script src="../plugin/jquery-zoomify/zoomify.min.js"></script>
    <script src="../plugin/jquery-3.2.1/jquery.serializejson.js"></script>
    <script src="../plugin/soul/utils3.js"></script>
    <script src='../base/base.js'></script>
</head>
<body>

<script>
    $(function () {
        var resp = AjaxUtil.isLogin();
        if (!resp) return;

        var module = 'withdraw_apply';

        var query = [];
        // 工具条配置
        var toolbar = {
            default: [false, false, false, false],// back;add;edit;remove
            dialog: [50, 2, 9],//对话框参数:模态框宽度(百分比);表单标题宽度;表单输入框宽度
            extra: [{
                name: '转币完成(已经手动处理)',
                glyphicon: 'ok',
                onclick: 'transferSuccess'
            }, {
                name: '转币错误(审核不通过)',
                glyphicon: 'remove',
                onclick: 'transferError'
            }, {
                name: '提交自动转币',
                glyphicon: 'bitcoin',
                onclick: 'submitTransaction'
            }]
        };
        var bootstrapTable = {
            columns: [{
                radio: true
            }, {
                field: 'withdrawId',
                title: '申请编号'
            }, {
                field: 'email',
                title: '用户邮箱'
            }, {
                field: 'address',
                title: '提币地址'
            }, {
                field: 'type',
                title: '提币类型',
                formatter: function (value) {
                    if (value == 100) {
                        return 'BHPC';
                    } else if (value == 110) {
                        return 'BHPC Bonus'
                    } else if (value == 10) {
                        return 'BTC'
                    } else if (value == 20) {
                        return 'ETH'
                    }else if (value == 30) {
                        return 'BCD'
                    }else if (value == 40) {
                        return 'BU'
                    }
                }
            }, {
                field: 'transctionStatus',
                title: '自动转币状态',
                formatter: function (value) {
                    if (value == -1) {
                        return '未知错误';
                    } else if (value == 0) {
                        return '还未提交'
                    } else if (value == 1) {
                        return '等待以太坊确定中'
                    } else if (value == 2) {
                        return '自动转币成功'
                    } else if (value == 3) {
                        return '自动转币失败<br>请确定后再次提交转币'
                    }else if (value == 4) {
                        return '正在执行自动转币'
                    }
                }
            }, {
                field: 'amount',
                title: '提币数量'
            }, {
                field: 'feeAmount',
                title: '提币手续费'
            }, {
                field: 'actualAmount',
                title: '实际到账'
            }, {
                field: 'lockDate',
                title: '用户锁期时间',
                formatter: function (value, row, index) {
                    return formatLockTime(value);
                },
            }, {
                field: 'createDate',
                title: '申请时间',
                formatter: BootstrapTableUtil.formatter.datetime
            }]
        };
        var formElement = [];
        withdraw_apply = SingleTablePageCreateUtil.createInstance(module, query, toolbar, formElement, bootstrapTable);

        withdraw_apply.submitTransaction = function () {
            var row = TablePageCreatePublicUtil.getRowFromTable('#withdraw_apply_table');
            if (!row) return false;
            if (row.status != 0) {
                SwalUtil.error("请不要重复审核");
                return;
            }


            var resp = AjaxUtil.postJson('withdraw_apply/submit_auto_transaction', {
                withdrawId: row.withdrawId,
            });
            if (resp) {
                SwalUtil.success(resp.msg);
                $('#withdraw_apply_table').bootstrapTable('refresh');
            }
        }

        withdraw_apply.transferSuccess = function () {
            var row = TablePageCreatePublicUtil.getRowFromTable('#withdraw_apply_table');
            if (!row) return false;
            if (row.status != 0) {
                SwalUtil.error("请不要重复审核");
                return;
            }
            var resp = AjaxUtil.postJson('withdraw_apply/transfer_success', {
                withdrawId: row.withdrawId,
            });
            if (resp) {
                SwalUtil.success(resp.msg);
                $('#withdraw_apply_table').bootstrapTable('refresh');
            }
        }

        withdraw_apply.transferError = function () {
            var row = TablePageCreatePublicUtil.getRowFromTable('#withdraw_apply_table');
            if (!row) return false;
            if (row.status != 0) {
                SwalUtil.error("请不要重复审核");
                return;
            }
            swal({
                title: '请输入错误理由:',
                input: 'text',
                showCancelButton: true,
                confirmButtonText: '确定',
                showLoaderOnConfirm: true,
                // preConfirm: function(text) {
                //     return new Promise(function(resolve, reject) {
                //         setTimeout(function() {
                //             if (email === 'taken@example.com') {
                //                 reject('该email已存在。');
                //             } else {
                //                 resolve();
                //             }
                //         }, 2000);
                //     });
                // },
                allowOutsideClick: false
            }).then(function (reason) {
                var resp = AjaxUtil.postJson('withdraw_apply/transfer_error', {
                    withdrawId: row.withdrawId,
                    reason: reason
                });
                if (resp) {
                    SwalUtil.success(resp.msg);
                    $('#withdraw_apply_table').bootstrapTable('refresh');
                }
            });

        }


    });

    formatLockTime = function (ms) {
        //获取当前系统时间
        var timestamp = new Date().getTime()

        if (isNaN(ms)) { //不是一个数字(时间戳),返回原值
            return "无";
        }
        if (null == ms) {
            return "无";
        }

        var diff = ms - timestamp; //用户锁期时间与当前时间的差值
        var oneDay = 24 * 60 * 60 * 1000; //一天的时间搓

        //如果当前时间大于锁期时间返回无
        if (diff < 0) {
            return "无"
        }
        var remainder = diff % oneDay;

        if (remainder == 0) {
            return parseInt(diff / oneDay) + "天"
        } else {
            return (parseInt(diff / oneDay) + 1) + "天"
        }
    }
</script>
</body>

</html>